package com.fr.report.script.function;

import com.fr.report.script.Function;
import com.fr.report.script.Function.Type;
import com.fr.report.script.NormalFunction;
import com.fr.report.script.Primitive;
import com.fr.report.script.core.FunctionHelper;
import com.fr.util.Utils;

public class LOG extends NormalFunction
{
  public Object run(Object[] paramArrayOfObject)
  {
    if (paramArrayOfObject.length < 1)
      return Primitive.ERROR_NAME;
    double d1 = Utils.objectToNumber(paramArrayOfObject[0], false).doubleValue();
    double d2 = (paramArrayOfObject.length < 2) ? 10.0D : Utils.objectToNumber(paramArrayOfObject[1], false).doubleValue();
    return FunctionHelper.parsePrimitiveDouble(Math.log(d1) / Math.log(d2));
  }

  public Function.Type getType()
  {
    return Function.MATH;
  }

  public String getCN()
  {
    return "LOG(number,base): 按指定的任意底数，返回数值的对数。\nNumber:需要求对数的正实数。\nBase:对数的底数。如果省略底数，默认值为10。\n示例:\nLOG(16,2)等于4。\nLOG(10)等于1。\nLOG(24,3)等于2.892789261。";
  }

  public String getEN()
  {
    return "LOG(number,base): Returns the logarithm of a number to the base you specify.\nNumber is the positive real number for which you want the logarithm.\nBase is the base of the logarithm. If base is omitted, it is assumed to be 10.\n\nExample:\n   LOG(16,2) = 4\n   LOG(10) = 1\n   LOG(24,3) = 2.892789261";
  }
}